1. Field of the Invention
The present invention relates to objects defined within an object-oriented computer programming system. More specifically, the present invention relates to a method and apparatus for storing long-lived objects within an object-oriented computer programming system.
2. Related Art
The recent proliferation of ever smaller and more capable computing devices has lead to the use of platform-independent programming languages on these smaller devices. Platform-independent programming languages facilitate the creation of programs that can be compiled to a set of platform-independent codes, which can be executed on a variety of computing devices. Many of these computing devices have a virtual machine (VM) containing an interpreter or just-in-time compiler to execute these platform-independent codes. The JAVA(trademark) programming language is an example of a platform-independent programming language and JAVA bytecodes are an example of platform-independent codes.
The terms JAVA, JVM and JAVA VIRTUAL MACHINE are registered trademarks of SUN Microsystems, Inc. of Palo Alto, Calif.
Many VMs use an area of memory called a heap to store various objects. When an object in the heap is no longer needed, all references pointing to the object will have been deleted. However, the object continues to occupy space in the heap. In some VMs, a computer program called a garbage collector scans the heap and deletes objects that are not being referenced in order to reclaim unused space in the heap.
There are many implementations of garbage collectors, however, they all share some traits. Garbage collectors require resources of the computing device in order to operate, thereby using storage space and slowing execution times of running programs. There have been many attempts to reduce the impact of garbage collection on executing programs. For instance, a garbage collector can be run in a separate execution thread. If the computing device has more than one processor, the separate execution thread can run on another processor, thereby reducing the impact on the main execution thread.
Another attempt to reduce the impact of garbage collection involves the use of so called xe2x80x9cgenerational garbage collectors.xe2x80x9d These work by migrating long-lived objects to an area of the heap where garbage collection is performed less often.
Neither of these techniques, however, is well suited for small computing devices. Small computing devices have only one processor, therefore running a separate garbage collection thread causes the main program thread to be xe2x80x9cswapped outxe2x80x9d during garbage collection. Furthermore, generational garbage collectors require large amounts of storage space, which may not be available on a small computing device.
Moreover, during initialization, many VMs generate a large number of objects that will remain active during the lifetime of the VM. For example, the JAVA runtime environment creates a large number of java.lang.String objects, which remain available for the duration of the program. These objects occupy a considerable portion of the heap and, as a result, cause the garbage collector to consume a considerable amount of processor time, even though these objects are never removed by the garbage collector.
What is needed is a system that eliminates the waste of resources caused by the garbage collector operating on objects that will never be deleted.
One embodiment of the present invention provides a system for storing long-lived objects defined within an object-oriented programming system. These long-lived objects are created in a virtual machine used for executing platform-independent code and are ordinarily created during initialization of the virtual machine. The system works by allocating a storage area reserved for long-lived objects that is not subject to garbage collection. After the storage area is allocated, the system receives requests to create an object. The system then determines if the object is a long-lived object by referring to a table of long-lived objects. If the object is a long-lived object, it is created and placed in the reserved storage area.
In one embodiment of the present invention, the reserved storage area is an area of a heap used by the virtual machine.
In one embodiment of the present invention, the remainder of the heap is subject to garbage collection.
In one embodiment of the present invention, the long-lived object is a persistent string object.
In one embodiment of the present invention, the persistent string object is a java.lang.String object.
In one embodiment of the present invention, the system closes the reserved storage area to new objects when initialization of the virtual machine is complete.
In one embodiment of the present invention, the system allows a garbage collector to reclaim unused storage in the reserved storage area one time just prior to closing the storage area.
In one embodiment of the present invention, the virtual machine is a JAVA VIRTUAL MACHINE.